<?php
/*****************************************
Wer Wird Millionär
TIT10NS Webengeneering Projekt

newquestion - Seite um neue Fragen anzulegen

Autoren: Markus Schwarz
Copyright: 2012/2013 DHBW Mannheim
*****************************************/
include ("inc/startup.php");
include ("inc/header.php");
require ("inc/TAdminQuestion.php");
require ("inc/TAdminNotification.php");
require ("inc/TAdminView.php");

if (isset($_POST['questionButton'])) {
	// Abfrage der eingegebenen Werte	
	$question = new TAdminQuestion( "new",
									$_POST["questiontext"],
									$_POST["right"],
									$_POST["wrong1"],
									$_POST["wrong2"],
									$_POST["wrong3"],
									$_POST["difficulty"],
									"");
	
	if (isset($_POST["categories"])) {
		$question->setCategories($_POST["categories"]);
		
						  
		// Wird nur ausgefuehrt, wenn alle Felder ausgefuellt wurden
		if( ($question->getQuestionText() != "") AND 
			($question->getRight() != "") AND 
			($question->getWrong1() != "") AND 
			($question->getWrong2() != "") AND 
			($question->getWrong3() != ""))
		{
			TModel::insertQuestion($question, 'insert');
			
			$notification = new TAdminNotification ("success", "newQuestionFormSuccess");
			TAdminView::getQuestionForm($question, $notification);
		}
		else {				  
			// Ansprechen der View um das Formular abzurufen
			$notification = new TAdminNotification ("error", "newQuestionFormTextEmpty");
			TAdminView::getQuestionForm($question, $notification);
		}
	}
	else {					  
		// Ansprechen der View um das Formular anzuzeigen
		$notification = new TAdminNotification ("error", "newQuestionFormCategoryEmpty");
		TAdminView::getQuestionForm($question, $notification);
	}
	
}
else {
	$question = new TAdminQuestion("new","","","","","","","");
	$notification = new TAdminNotification ("", "");
	
	// Ansprechen der View um das Formular anzuzeigen
	TAdminView::getQuestionForm($question, $notification);
}

include ("inc/footer.php");
?>
